//
//  LGTopic.m
//  lgdw
//
//  Created by mac on 16/1/16.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "LGTopic.h"


@implementation LGTopic

+ (instancetype)topicWithDict:(NSDictionary *)dict {
    LGTopic *topic = [[self alloc] init];
    [topic setValuesForKeysWithDictionary:dict];
    
    return topic;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{}

+ (void)topicWithSuccessBlock:(void (^)(NSArray *))successBlock errorBlock:(void (^)(NSError *))errorBlock {
    NSDictionary *parameter =
    // 未登录获取的数据
    @{@"Appid":@"10000024",
      @"Appkey":@"e93b6295c8143f2805c2c3013390d344",
      @"act":@"lists",
      @"client_ver":@"1.2.1",
      @"mid":@"0feab903c30b8d91f8ba9d46c153e1de93c2055e",
      @"page":@"0",
      @"platform":@"iPhone9.1",
      @"yd_auth":@"",
      @"yd_key":@"",
      @"yd_uid":@""};
    // 登陆
    //    @{@"Appid":@"10000024",
    //      @"Appkey":@"e93b6295c8143f2805c2c3013390d344",
    //      @"act":@"lists",
    //      @"client_ver":@"1.2.1",
    //      @"mid":@"e553e2d24021fb8a156296b27e95fe3e4cf40791",
    //      @"page":@"0",
    //      @"platform":@"iPhone9.1",
    //      @"yd_auth":@"d4f6ZD7td1cA6eH0SFATxSF07DKOXB%2B7gHKhfLtmV8FYgoK%2BUm4Wp%2FCaZti6tWV75B%2FtEtCn12jixPPuZvdHoYAe%2FFntpIYn2dLpN89taV3K1vhT3Q%2BBDBixLRwmKZwel%2BXn",
    //      @"yd_key":@"9563klroXuyAUEc61OJWViLHGR%2BCzHgbhYmyhwkZYSJ3",
    //      @"yd_uid":@"7014"};
    
    [[LGNetworkTools sharedManager] POST:@"/topic" parameters:parameter constructingBodyWithBlock:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
        NSArray *array = responseObject[@"data"];
        
        // 字典转模型
        NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:10];
        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            LGTopic *topic = [LGTopic topicWithDict:obj];
            [mArray addObject:topic];
        }];
        
        if (successBlock) {
            successBlock(mArray.copy);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (errorBlock) {
            NSLog(@"topic网络%@",error);
        }
    }];
    
}

@end
